package com.shujia.day12;

import java.io.*;
import java.util.HashMap;

public class Demo13Stream2Reader {
    public static void main(String[] args) throws IOException {
        /*
            TODO 字节流和字符流之间的转换关系
         */
        FileInputStream fileInputStream = new FileInputStream("data/data.txt");// 字节流的操作类
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); // 转换流
        BufferedReader reader = new BufferedReader(inputStreamReader); // 字符流
        String readLine = null;
        // TODO 统计单词出现的次数？
        HashMap<String, Integer> hashMap = new HashMap<>();
        while ((readLine= reader.readLine()) != null){
            String[] words = readLine.split(" ");
            for (String word : words) {
                if (hashMap.containsKey(word)){
                    hashMap.put(word,hashMap.get(word)+1);
                }else {
                    hashMap.put(word,1);
                }

            }
        }
        System.out.println(hashMap);
    }
}
